<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="giit.computerbase.util.Application" %>
<%@ page import="java.io.File" %>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="java.text.NumberFormat" %>
<%@ page import="giit.computerbase.util.CheckFile" %>
<%@ page import="giit.computerbase.util.DealWithCharcter" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>新闻详情</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/signin.css" rel="stylesheet">

</head>

<body>
<%
    String title = request.getParameter("name");
    HashMap<String, Object> temp = null;
    ArrayList<HashMap<String, Object>> result = (ArrayList<HashMap<String, Object>>) request.getSession().getAttribute("search");
    String type = "";
    boolean flag = true;
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    if (title != null && !title.equals("")) {
        title = URLDecoder.decode(title, "utf-8");
        title = DealWithCharcter.dealWith(title);
        Iterator<HashMap<String, Object>> iterator = result.iterator();
        while (iterator.hasNext()) {
            temp = iterator.next();
            if (temp.get("title").toString().equals(title)) {
                switch (temp.get("activity_type_id").toString()) {
                    case "type_01":
                        type = "普通";
                        break;
                    case "type_02":
                        type = "学术科技类";
                        break;
                    case "type_03":
                        type = "院级";
                        break;
                    case "type_04":
                        type = "省级";
                        break;
                    case "type_05":
                        type = "国家级";
                        break;
                }
                flag = false;
                break;
            }
        }
    }
    if (flag) {
    }
%>
<!-- page header start-->
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index">主页</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
            <ul class="nav navbar-nav navbar-right">
                <%
                    String user = (String) request.getSession().getAttribute("user");
                    if (user == null || user.equals("")) {
                %>
                <li><a href="login.jsp">登录</a></li>
                <li><a href="register.jsp">注册</a></li>
                <%
                } else {
                %>
                <li><a href=""><%=request.getSession().getAttribute("user")%>
                </a></li>
                <li><a href="edit.jsp">发新闻稿</a></li>
                <%
                    if ((boolean) request.getSession().getAttribute("manager")) {
                %>
                <li><a href="manager.jsp">管理</a></li>
                <%
                    }
                %>
                <li><a href="logout">退出</a></li>
                <%
                    }
                %>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</nav>
<!-- page header end-->


<div class="container" style="padding: 88px 0 0">

    <div class="col-xs-12 col-sm-12">
        <div class="panel panel-default">
            <!-- Default panel contents -->
            <div class="panel-heading"><%=temp.get("title")%>
            </div>
            <div class="panel-body">
                <p><%=temp.get("main")%>
                </p>
                <br><br>
                <p>附件下载</p>
                <%
                    File path = new File(Application.PATH + File.separator + "upload" + File.separator + title + File.separator);
                    if (path.exists()) {
                        File[] files = path.listFiles();
                        for (File file : files) {
                            if (!file.isHidden() && file.canRead()) {
                %>
                <a href="down?title=<%=title%>&name=<%=file.getName()%>" target="_blank"><%=file.getName()%>
                </a>&nbsp;&nbsp;&nbsp;&nbsp;[ 文件大小 <%=format.format(file.length() / (1024.0 * 1024)) %> mb ]
                <br><br>
                <%
                    }
                    if (CheckFile.check(file, CheckFile.$_JPG) || CheckFile.check(file, CheckFile.$_JPG)) {
                %>
                <%--<a href="show.jsp?title=<%=title%>&name=<%=file.getName()%>">[+] 预览</a>--%>
                <%
                            }
                        }
                    }
                %>
            </div>

            <!-- Table -->
            <table class="table">
                <thead>
                <tr>
                    <th>类型</th>
                    <th>撰稿人</th>
                    <th>撰稿时间</th>
                    <th>本稿发表时间</th>  <!--Offline match-->
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td><%=type%>
                    </td>
                    <td><%=temp.get("contributor")%>
                    </td>
                    <td><%=temp.get("feed_time")%>
                    </td>
                    <td><%=temp.get("date")%>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>

</div>

</div> <!-- /container -->

<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
